'use strict';
const requireEx=require('yi-require');

const handler = (req, res, next)=>{
    req.mongo.collection('card').updateMany({commentID:req.params.id},{$pull:{commentID:req.params.id}},(e1,r1)=>{
        req.mongo.collection('reply').deleteMany({commentID:req.params.id},(e0,r0)=>{
            req.mongo.collection("comment").deleteOne({_id: req.params.id}, (err, r)=> {
                if (err) return res.err.mongoError(err);
                if (r.deletedCount === 0) return res.err.nothingToDelete();
                res.reply({code:0,message:'删除成功',data:{deletedCount: r.deletedCount}});
            });
        });
    });
};

module.exports={
    open:false,
    description:'删除评论',
    handler:handler
};
